home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2005 June
/
ccd0605.iso
/
Software
/
Freeware
/
Programare
/
highlight
/
highlight-W32GUI-2.2-10b-Setup.exe
/
{app}
/
src
/
gui.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2005-04-27
|
43KB
|
1,002 lines
/***************************************************************************
gui.cpp - description
-------------------
begin : 06.08.02
copyright : (C) 2002 by AndrΘ Simon
email : andre.simon1@gmx.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "gui.h"
#include <wx/version.h>
#include "gui_failure_dlg.h"
using namespace std;
// Main Application
bool HighlightApp::OnInit()
{
HighlightFrame *win = new HighlightFrame(HIGHLIGHT_VERSION2);
if (win->getFatalError())return FALSE;
const wxCmdLineEntryDesc cmdLineDesc[] ={
{ wxCMD_LINE_PARAM, NULL, NULL, "input file", wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_NONE }
};
wxCmdLineParser parser(argc, argv);
parser.SetDesc(cmdLineDesc);
if (!parser.Parse() && parser.GetParamCount()){
wxArrayString inputFileList;
for (unsigned int i=0;i<parser.GetParamCount();i++){
inputFileList.Add(parser.GetParam(i));
}
win->addInputFiles(inputFileList, "");
}
win->Centre();
win->Show(TRUE);
SetTopWindow(win);
win->showStartupTips();
/* Do not return FALSE or the app will terminate immediately */
return TRUE;
}
// Main Window
HighlightFrame::HighlightFrame(const wxString &title)
: wxFrame((wxFrame *) NULL, -1, title, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_FRAME_STYLE),
fatalError(false),
#ifdef WIN32
preferencesPath(string(::wxGetHomeDir().c_str())+"\\highlight.conf"),
#else
preferencesPath(string(::wxGetHomeDir().c_str())+"/.wxhighlight"),
#endif
styleOutFileName(NULL),
language("English"),
i18n(NULL),
prefConf(NULL)
{
prefConf=new ConfigurationReader(preferencesPath);
if (prefConf!=NULL&& prefConf->found()){
language=prefConf->getParameter("language");
}
if (!loadLanguage(language)) {
fatalError=true;
}
#ifdef WIN32
SetIcon(wxIcon(::wxGetCwd()+"\\WinHighlight.ico", wxBITMAP_TYPE_ICO));
#else
//SetIcon(wxIcon(::wxGetCwd()+"/WinHighlight.xpm", wxBITMAP_TYPE_ICO));
#endif
outputFormats[0] = "HTML ";
outputFormats[1] = "XHTML";
outputFormats[2] = "LaTeX";
outputFormats[3] = "TeX";
outputFormats[4] = "RTF";
outputFormats[5] = "XSL-FO";
outputFormats[6] = "XML";
encodings[0] = "ISO-8859-1";
encodings[1] = "ISO-8859-2";
encodings[2] = "ISO-8859-3";
encodings[3] = "ISO-8859-4";
encodings[4] = "ISO-8859-5";
encodings[5] = "ISO-8859-6";
encodings[6] = "ISO-8859-7";
encodings[7] = "ISO-8859-8";
encodings[8] = "ISO-8859-9";
encodings[9] = "ISO-8859-10";
encodings[10] = "ISO-8859-11";
encodings[11] = "ISO-8859-13";
encodings[12] = "ISO-8859-14";
encodings[13] = "ISO-8859-15";
encodings[14] = "UFT-8";
menu1 = new wxMenu(),
menu3 = new wxMenu();
menu2 = new wxMenu();
MenuBar = new wxMenuBar();
// create a menu bar
menu1->Append(ID_MENU_OPENFILES,wxString(i18n->getCParameter ("m001")));
menu1->AppendSeparator();
menu1->Append(PROGRAM_QUIT,wxString(i18n->getCParameter ("m002")));
menu3->Append(ID_MENU_HELP, wxString(i18n->getCParameter("m003")));
menu3->Append(ID_MENU_TIPS, wxString(i18n->getCParameter("m009")));
menu3->AppendSeparator();
menu3->Append(ID_MENU_LICENSE, wxString(i18n->getCParameter("m004")));
menu3->Append(ID_MENU_CHANGELOG, wxString(i18n->getCParameter("m005")));
menu3->AppendSeparator();
menu3->Append(ID_MENU_ABOUT, wxString(i18n->getCParameter ("m006")));
wxFileName i18nFileName;
wxSortedArrayString i18nFiles;
wxDir::GetAllFiles(dataDir.getI18nDir().c_str(),
&i18nFiles, "*.txt", wxDIR_FILES);
if ( i18nFiles.IsEmpty())
{
wxMessageBox(wxString("i18n folder not found. Check installation."),
wxString("Error."),
wxICON_EXCLAMATION);
return;
}
// apart from English.txt, more translation files exist
bool translationsAvailable=i18nFiles.GetCount()>1;
if (translationsAvailable){
for (unsigned int i=0; i<i18nFiles.GetCount(); i++){
Connect(ID_MENU_LANGUAGE_DYN + i, -1, wxEVT_COMMAND_MENU_SELECTED,
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
&HighlightFrame::OnCheckLanguage);
i18nFileName.Assign(wxString(i18nFiles[i].c_str()));
menu2->AppendRadioItem(ID_MENU_LANGUAGE_DYN + i, i18nFileName.GetName());
}
menu2->Check(menu2->FindItem(wxString(language.c_str())), true);
}
// Add it to the menu bar
MenuBar->Append(menu1, wxString(i18n->getCParameter ("m007")));
MenuBar->Append(menu2, wxString(i18n->getCParameter ("m008")));
MenuBar->Append(menu3, wxString(i18n->getCParameter ("m003")));
SetMenuBar(MenuBar);
MenuBar->EnableTop(1, translationsAvailable);
panel =new wxPanel(this, ID_PANEL);
butSource = new wxButton(panel, ID_BUTTON_OPENFILES,
wxString(i18n->getCParameter ("l001")),
wxDefaultPosition, wxSize(125, 25), 0 );
listBox = new wxListBox(panel, ID_LISTBOX, wxDefaultPosition,
wxSize(200,390), 0, NULL,
wxLB_NEEDED_SB | wxLB_MULTIPLE | wxLB_HSCROLL);
butRemoveSelection=new wxButton(panel, ID_BUTTON_REMOVE,
wxString(i18n->getCParameter ("l033")),
wxDefaultPosition, wxSize(125, 25), 0 );
butClearList = new wxButton(panel, ID_BUTTON_CLEAR,
wxString(i18n->getCParameter ("l003")),
wxDefaultPosition, wxSize(125, 25), 0 );
// Spanish out directory label is very long, split in 2 lines
wxString outDirLbl;
outDirLbl.Printf(i18n->getCParameter ("l002"),"\n");
lblOutDir = new wxStaticText(panel, -1, outDirLbl);
outDir = new wxTextCtrl(panel, ID_OUTDIRTEXT, "", wxDefaultPosition,
wxSize(175, 22));
butOutDir = new wxButton( panel, ID_BUTTON_OUTDIR, "..." , wxDefaultPosition,
wxSize(20, 20), 0 );
writeToSourceDir= new wxCheckBox(panel, ID_WRITE_TO_SRCDIR,
wxString( i18n->getCParameter ("l032") ));
outputFormat = new wxRadioBox(panel, ID_OUTPUTFORMAT,
wxString(i18n->getCParameter("l004")),
wxDefaultPosition, wxDefaultSize, NUMBER_FORMATS,
outputFormats, 2,wxRA_SPECIFY_COLS);
linenumbers = new wxCheckBox(panel, ID_INCLUDELINENUMBERS,
wxString(i18n->getCParameter ("l013")));
attachAnchors= new wxCheckBox(panel, ID_ATTACHANCHORS,
wxString(i18n->getCParameter ("l006")));
lnFillZeroes = new wxCheckBox(panel, ID_FILL_ZEROES,
wxString(i18n->getCParameter ("l031")));
wrapLines= new wxCheckBox(panel, ID_WRAP,
wxString(i18n->getCParameter ("l027")));
wrapLinesCautious= new wxCheckBox(panel, ID_WRAP_CAUTIOUS,
wxString(i18n->getCParameter ("l028")));
fragment = new wxCheckBox(panel, ID_FRAGMENT,
wxString(i18n->getCParameter ("l014")));
includeStyle = new wxCheckBox(panel, ID_INCLUDECSS,
wxString(i18n->getCParameter ("l005")));
generateHtmlIndex=new wxCheckBox(panel, ID_GENERATEINDEX,
wxString(i18n->getCParameter ("l008")));
replaceLatexQuotes=new wxCheckBox(panel, ID_REPLACE_QUOTES,
wxString(i18n->getCParameter ("l029")));
lblColourTheme= new wxStaticText(panel, -1, wxString(i18n->getCParameter ("l010")));
themeChoice=new wxChoice(panel, ID_THEMECHOICE, wxDefaultPosition,
wxSize(100, 22));
reformatCode= new wxCheckBox(panel, ID_REFORMATCODE,
wxString(i18n->getCParameter ("l007")),
wxDefaultPosition, wxSize(80, 22));
formatChoice=new wxChoice(panel, ID_FORMATCHOICE, wxDefaultPosition,
wxSize(55, 22));
lblTabWidth=new wxStaticText(panel, -1, wxString(i18n->getCParameter ("l030")));
tabWidth= new wxSpinCtrl(panel, ID_TAB_WIDTH,"4", wxDefaultPosition,
wxSize(40, 22), wxSP_ARROW_KEYS, 0, 8 );
useEncoding= new wxCheckBox(panel, ID_USE_ENCODING,
wxString(i18n->getCParameter ("l036")),
wxDefaultPosition, wxSize(80, 22));
encodingChoice=new wxComboBox(panel, ID_ENCODING_LIST, "",wxDefaultPosition,
wxSize(85, 22), NUMBER_ENCODINGS, encodings,
wxCB_DROPDOWN | wxCB_SORT );
encodingChoice->SetSelection(0);
wxString str;
str.Printf("%s %s", i18n->getCParameter ("l011"),
((styleOutFileName!=NULL)?(styleOutFileName->GetValue()).c_str():
CSS_DEFAULT_NAME));
lblStyleIn= new wxStaticText(panel, -1,str);
styleInFileName = new wxTextCtrl(panel, ID_CSS_INFILE, "",
wxDefaultPosition,wxSize(120, 22));
butChooseStyleInfile = new wxButton( panel, ID_BUTTON_OPEN_CSS_INFILE, "...",
wxDefaultPosition, wxSize(20, 20), 0);
lblStyleOut= new wxStaticText(panel, -1, wxString(i18n->getCParameter ("l009")));
styleOutFileName = new wxTextCtrl(panel, ID_CSS_OUTFILE, CSS_DEFAULT_NAME,
wxDefaultPosition,wxSize(150, 22));
butStart = new wxButton(panel, ID_START, wxString(i18n->getCParameter("l015")),
wxDefaultPosition, wxSize(150, 30), 0 );
butStart->SetFont(wxFont(11, wxDEFAULT , wxNORMAL,wxBOLD));
progress= new wxGauge(panel, ID_PROGRESS, 100, wxDefaultPosition,
wxSize(150, 20),wxGA_SMOOTH );
// Layout ***************************************************************
wxBoxSizer *leftsizer = new wxBoxSizer( wxVERTICAL );
leftsizer->Add( butSource, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
// create text ctrl with minimal size 100x60
leftsizer->Add(
listBox,
1, // make vertically stretchable
wxGROW | // make horizontally stretchable
wxALL, // and make border all around
10 ); // set border width to 10
leftsizer->Add( butRemoveSelection, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
leftsizer->Add(butClearList, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
leftsizer->Add(0,10);
wxStaticBox *outDirBox= new wxStaticBox(panel, -1, "" );
wxStaticBoxSizer *outDirBoxSizer = new wxStaticBoxSizer( outDirBox, wxVERTICAL );
wxBoxSizer* outDirSelSizer = new wxBoxSizer(wxHORIZONTAL);
outDirSelSizer->Add( outDir, 1, wxALIGN_CENTRE|wxALL , 5 );
outDirSelSizer->Add( butOutDir, 0, wxALIGN_CENTER_VERTICAL|wxTOP, 0 );
outDirBoxSizer->Add( lblOutDir, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2 );
outDirBoxSizer->Add( outDirSelSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 5);
outDirBoxSizer->Add( writeToSourceDir, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 5);
leftsizer->Add(outDirBoxSizer,0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
// wxBoxSizer *middlesizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer *rightsizer = new wxBoxSizer( wxVERTICAL );
rightsizer->Add(outputFormat, 0, wxTOP | wxGROW| wxALIGN_LEFT, 0 );
wxStaticBox *optBox= new wxStaticBox(panel, -1, "");
wxStaticBoxSizer *optBoxSizer = new wxStaticBoxSizer( optBox, wxVERTICAL );
optBoxSizer->Add(linenumbers, 0, wxALIGN_LEFT, 5 );
optBoxSizer->Add( attachAnchors, 0, wxTOP | wxALIGN_LEFT | wxLEFT, 5 );
optBoxSizer->Add( lnFillZeroes, 0, wxTOP | wxALIGN_LEFT | wxLEFT, 5 );
// optBoxSizer->Add( new wxStaticLine(panel, -1, wxDefaultPosition,
// wxDefaultSize, wxLI_HORIZONTAL ), 0, wxGROW|wxTOP|wxLEFT|wxRIGHT, 10 );
optBoxSizer->Add( wrapLines, 0, wxTOP | wxALIGN_LEFT, 10 );
optBoxSizer->Add( wrapLinesCautious, 0, wxTOP | wxALIGN_LEFT | wxLEFT, 5 );
// optBoxSizer->Add( new wxStaticLine(panel, -1, wxDefaultPosition,
// wxDefaultSize, wxLI_HORIZONTAL ), 0, wxGROW|wxTOP|wxLEFT|wxRIGHT, 10 );
optBoxSizer->Add( fragment, 0, wxTOP | wxALIGN_LEFT, 10 );
optBoxSizer->Add( includeStyle, 0, wxTOP | wxALIGN_LEFT, 5 );
optBoxSizer->Add( generateHtmlIndex, 0, wxTOP | wxALIGN_LEFT, 5 );
optBoxSizer->Add( replaceLatexQuotes, 0, wxTOP |wxBOTTOM| wxALIGN_LEFT, 5 );
rightsizer->Add(optBoxSizer,0, wxGROW|wxTOP, 5);
wxStaticBox *choicesBox= new wxStaticBox(panel, -1, "");
wxStaticBoxSizer *choicesBoxSizer = new wxStaticBoxSizer( choicesBox, wxVERTICAL );
wxBoxSizer *themeSizer = new wxBoxSizer(wxHORIZONTAL );
themeSizer->Add( lblColourTheme, 0, wxTOP | wxALIGN_CENTER_VERTICAL , 3 );
themeSizer->Add(5, 0, 1);
themeSizer->Add( themeChoice, 0, wxTOP , 5 );
choicesBoxSizer->Add( themeSizer, 0, wxTOP| wxBOTTOM |wxGROW );
choicesBoxSizer->Add( new wxStaticLine(panel, -1, wxDefaultPosition,
wxDefaultSize, wxLI_HORIZONTAL ), 0, wxGROW|wxTOP|wxLEFT|wxRIGHT, 5 );
wxBoxSizer *reformatSizer = new wxBoxSizer(wxHORIZONTAL );
reformatSizer->Add(reformatCode,0, wxTOP | wxALIGN_CENTER_VERTICAL, 5);
reformatSizer->Add(5, 0, 1);
reformatSizer->Add(formatChoice,0, wxTOP, 5);
choicesBoxSizer->Add( reformatSizer, 0, wxTOP |wxGROW, 5 );
choicesBoxSizer->Add( new wxStaticLine(panel, -1, wxDefaultPosition,
wxDefaultSize, wxLI_HORIZONTAL ), 0, wxGROW|wxTOP|wxLEFT|wxRIGHT, 5 );
wxBoxSizer *tabSizer = new wxBoxSizer(wxHORIZONTAL );
tabSizer->Add(lblTabWidth, 0, wxTOP|wxALIGN_CENTER_VERTICAL , 5);
tabSizer->Add(5, 0, 1);
tabSizer->Add(tabWidth, 0, wxTOP, 3);
choicesBoxSizer->Add( tabSizer, 0, wxTOP| wxBOTTOM| wxGROW, 5 );
choicesBoxSizer->Add( new wxStaticLine(panel, -1, wxDefaultPosition,
wxDefaultSize, wxLI_HORIZONTAL ), 0, wxGROW|wxTOP|wxLEFT|wxRIGHT, 5 );
wxBoxSizer *encodingSizer = new wxBoxSizer(wxHORIZONTAL );
encodingSizer->Add(useEncoding,0, wxTOP | wxALIGN_CENTER_VERTICAL, 5);
encodingSizer->Add(5, 0, 1);
encodingSizer->Add(encodingChoice,0, wxTOP, 5);
choicesBoxSizer->Add( encodingSizer, 0, wxTOP |wxGROW, 5 );
rightsizer->Add(choicesBoxSizer,0, wxGROW|wxTOP, 5);
wxStaticBox *styleOptBox= new wxStaticBox(panel, -1, "");
wxStaticBoxSizer *styleOptBoxBoxSizer = new wxStaticBoxSizer( styleOptBox, wxVERTICAL );
styleOptBoxBoxSizer->Add( lblStyleOut, 0 );
styleOptBoxBoxSizer->Add( styleOutFileName, 0, wxTOP | wxGROW | wxALIGN_LEFT, 5 );
styleOptBoxBoxSizer->Add( lblStyleIn, 0, wxTOP | wxALIGN_LEFT, 10 );
wxBoxSizer *styleInSizer = new wxBoxSizer(wxHORIZONTAL );
styleInSizer->Add( styleInFileName, 1, wxTOP | wxGROW | wxALIGN_LEFT, 5 );
styleInSizer->Add( butChooseStyleInfile, 0, wxBOTTOM|wxTOP| wxLEFT| wxALIGN_CENTER_VERTICAL, 5 );
styleOptBoxBoxSizer->Add( styleInSizer, 0, wxBOTTOM|wxGROW, 5);
rightsizer->Add(styleOptBoxBoxSizer,0, wxGROW|wxTOP, 5);
rightsizer->Add(0, 20, 1);
rightsizer->Add( butStart, 0, wxTOP | wxGROW, 10 );
rightsizer->Add( progress, 0, wxTOP | wxBOTTOM| wxGROW | wxALIGN_BOTTOM, 10 );
wxBoxSizer *panelsizer = new wxBoxSizer( wxHORIZONTAL );
panelsizer->Add(leftsizer, 1, wxGROW|wxRIGHT, 20);
panelsizer->Add(rightsizer, 0,wxGROW|wxRIGHT, 10);
panelsizer->SetSizeHints( this ); // set size hints to honour minimum size
panel->SetSizer( panelsizer ); // use the sizer for layout
// Create the status bar
CreateStatusBar(2);
SetStatusText(wxString(i18n->getCParameter("l024")),1);
fillChoiceCtrl(themeChoice, wxString(dataDir.getThemeDir().c_str()), "*.style");
fillChoiceCtrl(formatChoice, wxString(dataDir.getIndentSchemesDir().c_str()), "*.indent");
assignToolTip(butSource,"t001");
assignToolTip(butOutDir,"t002");
assignToolTip(butChooseStyleInfile,"t003");
assignToolTip(butClearList,"t004");
assignToolTip(styleOutFileName,"t005");
assignToolTip(styleInFileName,"t006");
assignToolTip(outDir,"t007");
assignToolTip(includeStyle,"t008");
assignToolTip(fragment,"t009");
assignToolTip(linenumbers,"t010");
assignToolTip(attachAnchors,"t011");
assignToolTip(reformatCode,"t012");
assignToolTip(outputFormat,"t013");
assignToolTip(butStart,"t014");
assignToolTip(generateHtmlIndex,"t015");
assignToolTip(formatChoice,"t016");
assignToolTip(themeChoice,"t017");
assignToolTip(wrapLines,"t018");
assignToolTip(wrapLinesCautious,"t019");
assignToolTip(replaceLatexQuotes,"t020");
assignToolTip(tabWidth,"t021");
assignToolTip(lnFillZeroes,"t022");
assignToolTip(writeToSourceDir,"t023");
assignToolTip(butRemoveSelection,"t024");
assignToolTip(useEncoding,"t025");
applyPreferences();
plausiChecks();
fileFilter=wxString(readFile(dataDir.getExtDir()+"fileopenfilter.conf").c_str());
if (fileFilter.empty()){
fileFilter="All source code (*.*)|*.*|";
}
bool extensionsFound=loadFileExtensions();
if (!extensionsFound){
wxMessageBox(wxString(i18n->getCParameter ("e008")),
wxString(i18n->getCParameter ("l025")),
wxICON_EXCLAMATION);
}
// initialize drag and drop
listBox->SetDropTarget (new DropFiles (this));
}
void HighlightFrame::assignToolTip(wxWindow* widget, const char* tipName){
widget ->SetToolTip(wxString(i18n->getCParameter(tipName)));
}
void HighlightFrame::fillChoiceCtrl(wxChoice* choice, const wxString &dir, const wxString &ext){
if (!choice) return;
wxFileName fName;
wxSortedArrayString files;
wxDir::GetAllFiles(dir, &files, ext);
for (unsigned int i=0;i<files.GetCount(); i++){
fName.Assign(files[i]);
choice->Append(fName.GetName());
}
choice->SetSelection(0);
}
void HighlightFrame::showStartupTips(bool forceTips){
if (showTips || forceTips ){
wxString tipsFile;
const char *i18nPath = dataDir.getI18nDir().c_str();
tipsFile.Printf("%s%s.tips",i18nPath, language.c_str());
if (!::wxFileExists(tipsFile)){
tipsFile.Printf("%s%s.tips", i18nPath, "English");
}
wxTipProvider *tipProvider = wxCreateFileTipProvider(tipsFile, lastTip);
showTips=wxShowTip(this, tipProvider,showTips);
lastTip=tipProvider->GetCurrentTip();
delete tipProvider;
}
}
void HighlightFrame::OnTips(wxCommandEvent & WXUNUSED(event)){
showStartupTips(true);
}
bool HighlightFrame::loadLanguage(const string &newLanguage){
wxString i18nPath;
i18nPath.Printf("%s%s.txt",dataDir.getI18nDir().c_str(), newLanguage.c_str() );
delete i18n;
i18n= new ConfigurationReader(i18nPath.c_str());
if (!i18n->found()){
wxString errMsg;
errMsg.Printf("Could not load GUI language file (%s). Check installation.",
i18nPath.c_str());
wxMessageBox(errMsg, "Highlight Fatal Error", wxICON_EXCLAMATION);
return false;
}
language=newLanguage;
return true;
}
string HighlightFrame::readFile(const string &path, bool keepNewLine){
ifstream in (path.c_str());
string content;
if (in) {
string line;
unsigned int firstNonWs;
while (getline(in, line)) {
firstNonWs = line.find_first_not_of("\t ");
if ((firstNonWs!=string::npos) && (line[firstNonWs]!='#')){
content +=line;
if (keepNewLine) {
content +="\n";
}
}
}
}
return content;
}
bool HighlightFrame::loadFileExtensions(){
ConfigurationReader extensionsConfig(dataDir.getExtDir() + "extensions.conf");
if (extensionsConfig.found())
{
stringstream values;
string paramName, paramVal;
for (unsigned int i=0;i<extensionsConfig.getParameterNames().size();i++)
{
paramName = extensionsConfig.getParameterNames()[i];
values.str(extensionsConfig.getParameter(paramName)) ;
while (values >> paramVal) {
extensions[ paramVal ] = paramName;
}
values.clear();
}
return true;
}
return false;
}
void HighlightFrame::OnClickButtonSource(wxCommandEvent & WXUNUSED(event))
{
wxArrayString chosenFiles;
wxFileDialog openFiles(this,wxString(i18n->getCParameter("l018")),
openFileDir, "",
fileFilter,
wxMULTIPLE | wxFILE_MUST_EXIST);
openFiles.ShowModal();
openFiles.GetFilenames(chosenFiles);
openFileDir=openFiles.GetDirectory();
if (openFileDir[openFileDir.length()-1] != Platform::pathSeparator ) {
openFileDir += Platform::pathSeparator;
}
if (outDir->GetValue().IsEmpty()){
outDir->SetValue(openFileDir);
}
addInputFiles(chosenFiles, openFileDir);
}
void HighlightFrame::addInputFiles(const wxArrayString& inputFiles,
const wxString &prefix){
wxString absInFilePath;
for (unsigned int i=0; i< inputFiles.GetCount(); i++){
absInFilePath.Printf("%s%s", prefix.c_str(), inputFiles[i].GetData());
if (listBox->FindString(absInFilePath) == -1) {
listBox->Append(absInFilePath);
}
}
}
void HighlightFrame::OnClickButtonTargetDir(wxCommandEvent & WXUNUSED(event))
{
wxDirDialog targetDir(this,wxString(i18n->getCParameter("l002")), "");
targetDir.ShowModal();
outDir->SetValue(targetDir.GetPath());
}
void HighlightFrame::OnClickButtonClear(wxCommandEvent & WXUNUSED(event)){
listBox->Clear();
}
void HighlightFrame::OnClickButtonRemSelection(wxCommandEvent &event){
wxArrayInt selectedItems;
listBox->GetSelections (selectedItems);
size_t cnt = selectedItems.GetCount();
if (cnt){
for (size_t i=0;i<cnt;i++){
listBox->Delete(selectedItems[i]-i);
}
}
}
void HighlightFrame::OnHelp(wxCommandEvent & WXUNUSED(event)){
showTextFile("README.txt");
}
void HighlightFrame::OnLicense(wxCommandEvent & WXUNUSED(event)){
showTextFile("COPYING.txt");
}
void HighlightFrame::OnChangelog(wxCommandEvent & WXUNUSED(event)){
showTextFile("ChangeLog.txt");
}
void HighlightFrame::OnCheckLanguage(wxCommandEvent & event){
bool langFound=loadLanguage(menu2->GetLabel( event.GetId()).c_str());
if (langFound){
wxMessageBox(wxString(i18n->getCParameter("l026")),
wxString(i18n->getCParameter("l019")),
wxICON_INFORMATION);
}
}
void HighlightFrame::OnAbout(wxCommandEvent & WXUNUSED(event)){
string translatorsList=readFile(dataDir.getI18nDir()+"Translators.list", true);
if (translatorsList.empty()){
translatorsList="Error: File "+dataDir.getI18nDir()+
"Translators.list not found.\n";
}
formatMsg.Printf(MSG_INFO_TXT, HIGHLIGHT_VERSION, wxMAJOR_VERSION,
wxMINOR_VERSION, wxRELEASE_NUMBER,
translatorsList.c_str(),HIGHLIGHT_URL);
wxMessageBox(formatMsg,wxString(i18n->getCParameter("l019")),
wxICON_INFORMATION);
}
void HighlightFrame::showTextFile(const wxString &file){
wxString cmd="notepad ";
cmd.Printf("notepad %s%c%s",dataDir.getDir().c_str(),Platform::pathSeparator,file.c_str());
long result = wxExecute(cmd, true);
if (result == -1){
wxMessageBox(wxString(i18n->getCParameter("e001")),
wxString(i18n->getCParameter("l025")), wxICON_EXCLAMATION);
}
}
void HighlightFrame::plausiChecks(){
bool webOutput=(outputFormat->GetSelection()<2);
bool extStyleEnabled=(outputFormat->GetSelection()<4);
bool write2outdir = !writeToSourceDir ->GetValue();
includeStyle->Enable(extStyleEnabled || !write2outdir);
styleOutFileName->Enable(extStyleEnabled && !includeStyle->GetValue()&&write2outdir);
styleInFileName->Enable(extStyleEnabled);
lblStyleOut->Enable(extStyleEnabled&&!includeStyle->GetValue()&&write2outdir);
lblStyleIn->Enable(extStyleEnabled);
butChooseStyleInfile->Enable(extStyleEnabled);
attachAnchors->Enable(linenumbers->GetValue() && webOutput);
lnFillZeroes->Enable(linenumbers->GetValue());
formatChoice->Enable(reformatCode->GetValue());
wrapLinesCautious->Enable(wrapLines->GetValue());
replaceLatexQuotes->Enable(outputFormat->GetSelection()==2
&& fragment->GetValue());
lblTabWidth->Enable(!reformatCode->GetValue());
tabWidth->Enable(!reformatCode->GetValue());
generateHtmlIndex->Enable(webOutput && write2outdir);
lblOutDir ->Enable(write2outdir);
butOutDir->Enable(write2outdir);
outDir->Enable(write2outdir);
if (!write2outdir) includeStyle->SetValue(extStyleEnabled);
if (tabWidth->GetValue()<0)
tabWidth->SetValue(0);
else if (tabWidth->GetValue()>8)
tabWidth->SetValue(8);
if (extStyleEnabled){
checkStyleReferences(styleOutFileName, webOutput);
checkStyleReferences(styleInFileName, webOutput);
}
bool enableEncoding = outputFormat->GetSelection()<2
|| outputFormat->GetSelection()>4;
useEncoding->Enable(enableEncoding);
encodingChoice->Enable(enableEncoding && useEncoding->GetValue());
SetStyleInLabel();
}
void HighlightFrame::checkStyleReferences(wxTextCtrl *styleCtrl, bool webOutput){
wxString stylePath = styleCtrl->GetValue();
if (stylePath.Matches( (webOutput)? "*.sty" : "*.css")) {
stylePath.Printf((webOutput)?"%s.css":"%s.sty",
stylePath.Mid(0, stylePath.Length()-4).c_str());
styleCtrl->SetValue (stylePath);
}
}
void HighlightFrame::OnStyleOutfileChanged(wxCommandEvent & WXUNUSED(event)){
SetStyleInLabel();
}
void HighlightFrame::SetStyleInLabel(){
wxString str;
str.Printf("%s %s",i18n->getCParameter ("l011"),
( (includeStyle->GetValue()) ? i18n->getCParameter ("l035"):
((styleOutFileName!=NULL)?(styleOutFileName->GetValue()).c_str():
CSS_DEFAULT_NAME )));
lblStyleIn->SetLabel(str);
}
void HighlightFrame::OnClickButtonOpenStyleFile(wxCommandEvent & WXUNUSED(event))
{
wxArrayString chosenFiles;
wxFileDialog openFiles(this,i18n->getCParameter ("l018"),"", "",
"CSS input file (*.css)|*.css|",
wxMULTIPLE|wxFILE_MUST_EXIST );
openFiles.ShowModal();
wxString chosenFile=openFiles.GetDirectory();
chosenFile.Append(Platform::pathSeparator);
chosenFile.Append(openFiles.GetFilename());
styleInFileName->SetValue(chosenFile);
}
void HighlightFrame::OnQuit(wxCommandEvent & WXUNUSED(event))
{
if (!writePreferences()) {
wxMessageBox (wxString(i18n->getCParameter ("e006")),
wxString(i18n->getCParameter("l025")), wxICON_EXCLAMATION);
}
if (i18n) delete i18n;
if (prefConf) delete prefConf;
this->Destroy();
}
bool HighlightFrame::writePreferences(){
if (!fatalError) {
ofstream pref (preferencesPath.c_str());
if (!pref.fail()){
pref << "# WinHighlight Preferences - Please do not edit unless you know "
<< "what you're doing";
pref << "\n$outdir="<<outDir->GetValue().c_str();
pref << "\n$outputformat="<< outputFormat->GetSelection() ;
pref << "\n$outcssfile="<<(styleOutFileName->GetValue()).GetData();
pref << "\n$incssfile="<<(styleInFileName->GetValue()).GetData();
pref << "\n$themechoice="<<themeChoice->GetSelection();
pref << "\n$openfiledir="<<openFileDir.c_str();
pref << "\n$includecss="<<includeStyle->GetValue();
pref << "\n$fragment="<<fragment->GetValue();
pref << "\n$linenumbers="<<linenumbers->GetValue();
pref << "\n$attachanchors="<<attachAnchors->GetValue();
pref << "\n$reformatcode="<<reformatCode->GetValue();
pref << "\n$formatchoice="<<formatChoice->GetSelection();
pref << "\n$encodingval="<<encodingChoice->GetValue();
pref << "\n$useencoding="<<useEncoding->GetValue();
pref << "\n$generatehtmlindex="<<generateHtmlIndex->GetValue();
pref << "\n$wrap="<<wrapLines->GetValue();
pref << "\n$wrapsimple="<<wrapLinesCautious->GetValue();
pref << "\n$replacequotes="<<replaceLatexQuotes->GetValue();
pref << "\n$language="<<language;
pref << "\n$showtips="<<showTips;
pref << "\n$lasttip="<<lastTip;
pref << "\n$tabwidth="<<tabWidth->GetValue();
pref << "\n$fillzeroes="<<lnFillZeroes->GetValue();
pref << "\n$write2src="<<writeToSourceDir->GetValue();
pref.close();
return true;
}
}
return fatalError;
}
bool HighlightFrame::applyPreferences(){
string trueStr("1");
if (prefConf != NULL && prefConf->found()){
outDir->SetValue(prefConf->getParameter("outdir").c_str());
outputFormat->SetSelection(StringTools::str2int(prefConf->
getParameter("outputformat")));
themeChoice->SetSelection(StringTools::str2int(prefConf->
getParameter("themechoice")));
openFileDir=prefConf->getParameter("openfiledir").c_str();
includeStyle->SetValue(prefConf->getParameter("includecss")==trueStr);
fragment->SetValue(prefConf->getParameter("fragment")==trueStr);
linenumbers->SetValue(prefConf->getParameter("linenumbers")==trueStr);
attachAnchors->SetValue(prefConf->getParameter("attachanchors")==trueStr);
reformatCode->SetValue(prefConf->getParameter("reformatcode")==trueStr);
generateHtmlIndex->SetValue(prefConf->
getParameter("generatehtmlindex")==trueStr);
wrapLines->SetValue(prefConf->getParameter("wrap")==trueStr);
wrapLinesCautious->SetValue(prefConf->
getParameter("wrapsimple")==trueStr);
replaceLatexQuotes->SetValue(prefConf->
getParameter("replacequotes")==trueStr);
formatChoice->SetSelection(StringTools::str2int(prefConf->
getParameter("formatchoice")));
language=prefConf->getParameter("language");
showTips=prefConf->getParameter("showtips")==trueStr;
lastTip= StringTools::str2int( prefConf->getParameter("lasttip"));
tabWidth->SetValue(wxString(prefConf->getCParameter("tabwidth")));
lnFillZeroes->SetValue(prefConf->getParameter("fillzeroes")==trueStr);
styleOutFileName->SetValue(prefConf->getParameter("outcssfile").c_str());
styleInFileName->SetValue(prefConf->getParameter("incssfile").c_str());
writeToSourceDir->SetValue(prefConf->getParameter("write2src")==trueStr);
encodingChoice->SetValue(wxString(prefConf->getCParameter("encodingval")));
useEncoding->SetValue(prefConf->getParameter("useencoding")==trueStr);
SetStyleInLabel();
return true;
}
return false;
}
highlight::OutputType HighlightFrame::getOutputType(){
switch (outputFormat->GetSelection()){
case 0: return highlight::HTML;
case 1: return highlight::XHTML;
case 2: return highlight::LATEX;
case 3: return highlight::TEX;
case 4: return highlight::RTF;
case 5: return highlight::XSLFO;
case 6: return highlight::XML;
}
return highlight::HTML;
}
void HighlightFrame::OnClickButtonStart(wxCommandEvent & WXUNUSED(event)){
if (!listBox->GetCount())
return;
if (!writeToSourceDir->GetValue() && !wxDir::Exists(outDir->GetValue()))
{
wxMessageBox(wxString(i18n->getCParameter("l020")),
wxString(i18n->getCParameter("l025")), wxICON_EXCLAMATION);
outDir->SetFocus();
return;
}
if (outputFormat->GetSelection()<2 && (includeStyle->GetValue()==false)
&&(styleOutFileName->GetValue().IsEmpty()))
{
wxMessageBox(wxString(i18n->getCParameter("l021")),
wxString(i18n->getCParameter("l025")), wxICON_EXCLAMATION);
styleOutFileName->SetFocus();
return;
}
wxStopWatch stopWatch;
string outPath((outDir->GetValue()).c_str());
if (outPath[outPath.length()-1] != Platform::pathSeparator ) {
outPath +=Platform::pathSeparator;
}
wxString stylePath;
stylePath.Printf("%s%s.style", dataDir.getThemeDir().c_str(),
themeChoice->GetStringSelection().c_str());
highlight::CodeGenerator *generator =
highlight::CodeGenerator::getInstance(getOutputType(),
stylePath.c_str(),
(styleInFileName->GetValue()).GetData(),
(styleOutFileName->GetValue()).GetData(),
(encodingChoice->GetValue()).GetData(),
includeStyle->GetValue(),
attachAnchors->GetValue(),
replaceLatexQuotes->GetValue(),
true,
tabWidth->GetValue(),
getWrappingStyle(),
linenumbers->GetValue(),
lnFillZeroes->GetValue(),
fragment->GetValue(),
!useEncoding->GetValue());
if (reformatCode->GetValue()){
wxString indentSchemePath;
indentSchemePath.Printf("%s%s.indent", dataDir.getIndentSchemesDir().c_str(),
formatChoice->GetStringSelection().c_str());
generator->initIndentationScheme(indentSchemePath.c_str());
}
string outfileName;
string langDefPath;
string suffix;
int fileCount=0;
highlight::ParseError error;
highlight::LoadResult loadRes;
wxArrayString reformatFailures, outputFailures, inputFailures;
wxString currentInputFile;
SetStatusText(wxString(i18n->getCParameter ("l017")),1);
wxBeginBusyCursor();
while( fileCount < listBox->GetCount())
{
currentInputFile= listBox->GetString(fileCount);
// dekl. aus schleife gezogen
suffix = getFileType(getFileSuffix(currentInputFile.c_str()));
langDefPath = dataDir.getLangDefDir() + suffix + ".lang";
loadRes= generator->initLanguage(langDefPath);
if (loadRes==highlight::LOAD_FAILED) {
formatMsg.Printf(wxString(i18n->getCParameter ("e002")),
suffix.c_str());
wxMessageBox(formatMsg, wxString(i18n->getCParameter("l025")),
wxICON_EXCLAMATION);
} else {
if (reformatCode->GetValue()&& !generator->formattingIsPossible()){
reformatFailures.Add(currentInputFile);
}
if (writeToSourceDir->GetValue()) { //write output to source directories?
outfileName = string(currentInputFile.c_str());
} else {
outfileName = outPath;
outfileName += wxFileName(currentInputFile).GetFullName().c_str();
}
outfileName += getOutFileSuffix();
error = generator->printOutput(currentInputFile.c_str(),
outfileName.c_str() );
if (error != highlight::PARSE_OK){
stopWatch.Pause();
if (error == highlight::BAD_INPUT) {
inputFailures.Add(currentInputFile);
}
else {
outputFailures.Add(wxString(outfileName.c_str()));
}
stopWatch.Resume();
}
progress->SetValue(100 * fileCount / listBox->GetCount());
}
++fileCount;
}
// print external style definition file
if (!includeStyle->GetValue()){
string css_name = (styleOutFileName->GetValue()).GetData();
string csspath = outPath;
unsigned int pos = css_name.find_last_of('\\');
if (pos == string::npos) {
pos = css_name.find_last_of('/');
}
if ((pos != string::npos) && (pos < css_name.length())) {
csspath += css_name.substr(pos+1, css_name.length());
} else {
csspath += css_name;
}
bool styleFileOK=generator -> printExternalStyle(csspath);
if (!styleFileOK) {
formatMsg.Printf(wxString(i18n->getCParameter("e004")),
styleInFileName->GetValue().GetData());
wxMessageBox(formatMsg, wxString(i18n->getCParameter("l025")),
wxICON_EXCLAMATION);
}
}
// print index file
if (generateHtmlIndex->GetValue() && !writeToSourceDir->GetValue()) {
vector <string> fileList;
for (int i=0; i < listBox->GetCount(); i++){
fileList.push_back(string(listBox->GetString(i)));
}
bool indexFileOK=generator->printIndexFile(fileList, outPath);
if (!indexFileOK) {
wxMessageBox(wxString(i18n->getCParameter("e007")),
wxString(i18n->getCParameter("l025")),
wxICON_EXCLAMATION);
}
}
highlight::CodeGenerator::deleteInstance();
formatMsg.Printf(i18n->getCParameter ("l023"), fileCount, stopWatch.Time());
progress->SetValue(0);
wxEndBusyCursor();
SetStatusText(formatMsg, 1);
if (!reformatFailures.IsEmpty()||
!inputFailures.IsEmpty() ||
!outputFailures.IsEmpty()) {
FailureDlg dlg(this, -1,wxString(i18n->getCParameter ("l034")),
wxString(i18n->getCParameter ("e010")), reformatFailures,
wxString(i18n->getCParameter ("e003")), inputFailures,
wxString(i18n->getCParameter ("e004")), outputFailures );
dlg.ShowModal() ;
}
}
highlight::WrapMode HighlightFrame::getWrappingStyle(){
if (wrapLinesCautious->GetValue()) return highlight::WRAP_SIMPLE;
return (wrapLines->GetValue())?highlight::WRAP_DEFAULT:highlight::WRAP_DISABLED;
}
string HighlightFrame::getFileType(const string& suffix)
{
return (extensions.count(suffix)) ? extensions[suffix] : suffix ;
}
string HighlightFrame::getFileSuffix(const string& fileName)
{
unsigned int ptPos=fileName.rfind(".");
return (ptPos == string::npos) ? "" : fileName.substr(ptPos+1,
fileName.length());
}
string HighlightFrame::getOutFileSuffix(){
switch (outputFormat->GetSelection()) {
case 0: return ".html";
case 1: return ".xhtml";
case 4: return ".rtf";
case 5: return ".fo";
case 6: return ".xml";
}
return ".tex";
}
bool DropFiles::OnDropFiles (wxCoord x, wxCoord y, const wxArrayString& filenames) {
for (size_t n = 0; n < filenames.Count(); n++) {
if (wxFileName(filenames[n]).IsDir()) {
wxMessageBox (_("Directories are not allowed!"),
_("Error"), wxOK | wxICON_EXCLAMATION);
return FALSE;
}
}
m_frame->addInputFiles(filenames, "");
return TRUE;
}